/*
 * Player.java
 *
 * Copyright(c) 2009 - Kimnach
 *
 * Description:
 *      Class for Players.- not fully implemented
 *
 */

package player;

import java.awt.Color;
import java.util.ArrayList;

/**
 *
 * @author dkimnach
 */
public class Player {
    private int health; // unused
    private int prestige; // unused
    private String name;
    private Color col;

    // states
    boolean dead;

    // interesting stats
    private int lostTurns;
    private ArrayList<Integer> initiatives = new ArrayList<Integer>(); // initiatives dealt
    private int halved; // how many times damage halved due to monster attacks

    public Player(String name, Color col) {
        this.name = name;
        health = 100;
        prestige = 0;
        dead = false;
        this.col = col;
    }
    
    public int addPrestige(int pres) {
        prestige += pres;
        return prestige;
    }
    
    public int removePrestige(int pres) {
        prestige += pres;
        return prestige;
    }
    
    public int damage(int dmg) {
        health -= dmg;
        if (health <= 0) {
            health = 0;
            this.die();
        }
        return health;
    }
    
    public int heal(int heal) {
        health += heal;
        if (health > 100) { health = 100; }
        return health;
    }

    public void die() {
        dead = true;
    }

    public void revive() {
        dead = false;
    }

    public boolean isDead() {
        return dead;
    }

    public int getHealth() {
        return health;
    }

    public Color getColor() {
        return col;
    }

    public int getPrestige() {
        return prestige;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        String player = name + "\n";
        player += "Lost " + lostTurns + " turns\n" ;
        //player += "Damage was halved " + halved + " times due to monster attacks\n";


        player += "Dealt Initiatives:\n";
        int ones = 0;
        int twos = 0;
        int threes = 0;
        int fours = 0;
        int fives = 0;
        int sixes = 0;
        for (int init : initiatives) {
            if (init == 1) {
                ones++;
            } else if (init == 2) {
                twos++;
            } else if (init == 3) {
                threes++;
            } else if (init == 4) {
                fours++;
            } else if (init == 5) {
                fives++;
            } else {
                sixes ++;
            }
        }
        player += "\t* " + ones + " ones\n";
        player += "\t* " + twos + " twos\n";
        player += "\t* " + threes + " threes\n";
        player += "\t* " + fours + " fours\n";
        player += "\t* " + fives + " fives\n";
        player += "\t* " + sixes + " sixes\n";

        return player;
    }
}
